﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.NeighborUI {
    import org.aswing.*;
    import Classes.*;
    import org.aswing.util.*;
    import org.aswing.ext.*;
    import Display.aswingui.*;

    public class FriendBarScrollingList extends JPanel {

        public static const SCROLL_VERTICAL:int = 0;
        public static const SCROLL_HORIZONTAL:int = 1;
        public static const NUM_ITEMS:int = 6;
        public static const ITEM_WIDTH:int = 76;
        public static const ITEM_OFFSET:int = 4;

        protected var m_dataList:GridList;
        protected var m_scrollPane:JScrollPane;
        protected var m_cellFactory:GridListCellFactory;
        protected var m_viewport:JViewport;
        protected var m_curLeftScrollNdx:int = -1;
        protected var m_frame:JWindow;
        protected var m_rows:int;
        protected var m_columns:int;
        protected var m_data:Array;
        protected var curCount:int = 0;
        protected var m_model:VectorListModel;

        public function FriendBarScrollingList(_arg1:Array){
            super(new FlowLayout(FlowLayout.LEFT, 0, 0));
            this.m_cellFactory = new FriendCellFactory();
            this.m_columns = NUM_ITEMS;
            this.m_rows = 1;
            this.m_data = _arg1;
            this.makeData();
            this.initSize();
            this.prepare();
        }
        protected function makeData():void{
            var _local1:int = Math.max((NUM_ITEMS + 1), this.m_data.length);
            this.m_model = new VectorListModel();
            var _local2:int;
            while (_local2 < _local1) {
                this.m_model.append(this.m_data[_local2]);
                this.curCount++;
                _local2++;
            };
            this.m_dataList = new GridList(this.m_model, this.m_cellFactory, this.m_columns, this.m_rows);
            this.m_dataList.setHGap(1);
            this.m_scrollPane = new JScrollPane(this.m_dataList, JScrollPane.SCROLLBAR_NEVER, JScrollPane.SCROLLBAR_NEVER);
            this.m_scrollPane.setPreferredWidth((NUM_ITEMS * (ITEM_WIDTH + ITEM_OFFSET)));
            this.m_scrollPane.setMaximumWidth((NUM_ITEMS * (ITEM_WIDTH + ITEM_OFFSET)));
            this.m_scrollPane.setMinimumWidth((NUM_ITEMS * (ITEM_WIDTH + ITEM_OFFSET)));
            this.m_curLeftScrollNdx = 0;
            this.moveRight((this.m_data.length - NUM_ITEMS));
        }
        public function get data():Array{
            return (this.m_data);
        }
        public function friendVisited(_arg1:String):void{
            var _local4:FriendCell;
            var _local2:ArrayList = this.m_dataList.getCells();
            var _local3:int;
            while (_local3 < _local2.size()) {
                _local4 = _local2.elementAt(_local3);
                if (_local4.m_friend.m_uid == _arg1){
                    _local4.clearNewFriend();
                };
                _local3++;
            };
        }
        public function set data(_arg1:Array):void{
            this.m_data = _arg1;
            this.curCount = 0;
            this.m_model.clear();
            var _local2:int = this.m_data.length;
            var _local3:int;
            while (_local3 < _local2) {
                this.m_model.append(this.m_data[_local3]);
                this.curCount++;
                _local3++;
            };
            var _local4:int = (this.m_data.length - NUM_ITEMS);
            this.m_curLeftScrollNdx = _local4;
            this.moveRight(_local4);
        }
        protected function prepare():void{
            this.append(this.m_scrollPane);
            ASwingHelper.prepare(this);
        }
        protected function initSize():void{
        }
        public function removeListeners():void{
        }
        protected function offsetAndloadPortraits(_arg1:int):void{
            var _local7:FriendCell;
            this.m_curLeftScrollNdx = (this.m_curLeftScrollNdx + _arg1);
            if (this.m_curLeftScrollNdx > (this.m_data.length - NUM_ITEMS)){
                this.m_curLeftScrollNdx = (this.m_data.length - NUM_ITEMS);
            };
            if (this.m_curLeftScrollNdx < 0){
                this.m_curLeftScrollNdx = 0;
            };
            var _local2:int = NUM_ITEMS;
            var _local3:int = ((this.m_curLeftScrollNdx + NUM_ITEMS) + _local2);
            var _local4:ArrayList = this.m_dataList.getCells();
            if (_local3 > _local4.size()){
                _local3 = _local4.size();
            };
            var _local5:int = (this.m_curLeftScrollNdx - _local2);
            if (_local5 < 0){
                _local5 = 0;
            };
            var _local6:int = _local5;
            while (_local6 < _local3) {
                _local7 = _local4.elementAt(_local6);
                _local7.loadNeighborPortrait();
                _local6++;
            };
        }
        public function moveLeft(_arg1:int):void{
            var _local2:int;
            if (_arg1 == 0){
                _local2 = this.m_curLeftScrollNdx;
                this.m_dataList.scrollHorizontal((-((ITEM_WIDTH + ITEM_OFFSET)) * _local2));
                this.offsetAndloadPortraits(-(_local2));
            } else {
                this.m_dataList.scrollHorizontal((-((ITEM_WIDTH + ITEM_OFFSET)) * _arg1));
                this.offsetAndloadPortraits(-(_arg1));
            };
        }
        public function moveRight(_arg1:int):void{
            var _local2:int;
            if (_arg1 == 0){
                _local2 = (this.m_data.length - NUM_ITEMS);
                this.m_dataList.scrollHorizontal(((ITEM_WIDTH + ITEM_OFFSET) * _local2));
                this.offsetAndloadPortraits(_local2);
            } else {
                this.m_dataList.scrollHorizontal(((ITEM_WIDTH + ITEM_OFFSET) * _arg1));
                this.offsetAndloadPortraits(_arg1);
            };
        }
        public function updateFriend(_arg1:Friend):void{
            var _local4:Object;
            var _local5:FriendCell;
            var _local2:ArrayList = this.m_dataList.getCells();
            var _local3:int;
            while (_local3 < _local2.size()) {
                _local4 = _local2.get(_local3);
                if (((_local4) && ((_local4 is FriendCell)))){
                    _local5 = (_local4 as FriendCell);
                    if (_local5.m_friend.uid == _arg1.uid){
                        _local5.removeAll();
                        _local5.setCellValue(_arg1);
                        _local5.showPic();
                        break;
                    };
                };
                _local3++;
            };
        }
        public function addfriendPeddlerIcon(_arg1:String):void{
            var _local4:FriendCell;
            var _local2:ArrayList = this.m_dataList.getCells();
            var _local3:int;
            while (_local3 < _local2.size()) {
                _local4 = _local2.elementAt(_local3);
                if (_local4.m_friend.m_uid == _arg1){
                    _local4.addPeddlerIcon();
                    break;
                };
                _local3++;
            };
        }
        public function hidePeddlerIcon(_arg1:String):void{
            var _local4:FriendCell;
            var _local2:ArrayList = this.m_dataList.getCells();
            var _local3:int;
            while (_local3 < _local2.size()) {
                _local4 = _local2.elementAt(_local3);
                if (_local4.m_friend.m_uid == _arg1){
                    _local4.hidePeddlerIcon();
                    break;
                };
                _local3++;
            };
        }

    }
}//package Display.NeighborUI 
